/*
* © 2010 Autodata Solutions Company. All Rights Reserved
* This source code is the confidential and proprietary information of Autodata Solutions Company.
* The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
* without the prior written consent of Autodata Solutions Company.
*/
Ext.ns('net.autodata.compare');
(function () {

	var DQ = Ext.DomQuery;
	
	/**
	 * An Abstract View for the VehiclePanel 
	 * @class AbstractVehicleView
	 * @extends net.autodata.AbstractView
	 * @namespace net.autodata.compare
	 */
	var AbstractView = Ext.extend(net.autodata.AbstractView, {
		
		vehicleInfo: undefined,
		vehicleInfoCfg: undefined,
		
		vehicleImage: undefined,
		
		/**
		 * This method should be called from the extending class to ensure the AbstractView's base class is 
		 * initialized correctly
		 * @method ctor
		 * @private
		 */
		ctor: function ()
		{
			this.addEvents({
				'change': true,
				'remove': true
			});
			AbstractView.superclass.ctor.apply(this, arguments);
		},
		
		/**
		 * @method init
		 */
		init: function ()
		{
			AbstractView.superclass.init.apply(this, arguments);
			
			this.component.on({
				'datachanged': this.refresh,
				scope: this
			});
			
			this.initComponents();
		},
		
		/**
		 * @method initComponents
		 */
		initComponents: function ()
		{			
			var vehicle = this.component.getVehicle();
			
			if (!this.vehicleImage) {
				this.vehicleImage = new net.autodata.IOFImage(Ext.apply({
					imageName: vehicle ? vehicle.selectedImageName || vehicle.imageName : undefined
				}, this.imageCfg));
			}
			
			if (!this.vehicleInfo) {
				var cfg = Ext.apply(this.vehicleInfoCfg || {}, {
					data: vehicle
				})
				this.vehicleInfo = new net.autodata.compare.VehicleInfoPanel(cfg);
			}
		},		
		
		/**
		 * Updates the vehicleInfo and vehicleImage widgets with the new vehicle record
		 * @method refresh
		 */
		refresh: function ()
		{
			AbstractView.superclass.refresh.apply(this, arguments);
			
			var vehicle = this.component.getVehicle();
			this.vehicleInfo.setData(vehicle);
			
			this.vehicleImage.setImageName(vehicle.selectedImageName || vehicle.imageName);
		},
		
		/**
		 * @method render
		 */
		render: Ext.emptyFn,
		
		/**
		 * Clean up any event bindings made by this View
		 * @method onDestroy
		 * @private
		 */
		onDestroy: function ()
		{
			AbstractView.superclass.onDestroy.apply(this, arguments);
			if (this.component) {
				this.component.un('datachanged', this.refresh, this);
			}
		}
	});
	
	net.autodata.compare.AbstractVehicleView = AbstractView;
})();